import Vue from 'vue';
import App from './App.vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);

// 懒加载
// public
const Index = resolve => {require.ensure([], () => {resolve(require('./components/common/index.vue'))})};
const Error404 = resolve => {require.ensure([], () => {resolve(require('./components/common/404.vue'))})};
// detail
const Foo = resolve => {require.ensure([], () => {resolve(require('./components/Foo.vue'))})};
const Bar = resolve => {require.ensure([], () => {resolve(require('./components/Bar.vue'))})};

const router = new VueRouter({
  routes: [
    {
      path: '/',
      component: Index,
      children: [
        // { path: '', component: Index },
        { path: 'home', component: Foo },
        { path: 'other', component: Bar }
      ]
    },
    {
      path: '/404',
      component: Error404,
    },
    {path: '*', redirect: '/404'}//放在最后
  ]
})

new Vue({
  el: '#app',
  router,
  render: h => h(App)
});
